<template>
  <div class="">
    <div class="info-title">比赛列表</div>
    <el-table style="width: 100%" border :data="tableData">
      <el-table-column :show-overflow-tooltip="true" prop="name"  width="300" label="比赛"></el-table-column>
      <el-table-column prop="joinStartTime" label="报名开始"></el-table-column>
      <el-table-column prop="joinEndTime" label="报名截止"></el-table-column>
      <el-table-column prop="status" label="状态"></el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.status != '报名中'"
            size="mini"
            type="success"
            @click="handleAgree(scope.$index, scope.row)">报名</el-button>
          <!-- <el-button
            size="mini"
            type="success"
            @click="handleAgree(scope.$index, scope.row)">报名</el-button> -->
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import searchTable from '@/components/PublicTable/index.vue'
import {getCompetitionList} from "@/api/competition";
import {getApplyCan} from "@/api/apply";
export default {
  components:{
    searchTable
  },
  data () {
    return {
      tableData:[],
      tableData: [],
      loading: false,
      tableRef: 'tableRef',
      searchForm: {},
      currentPage: 1,
      pageSizes: [10, 20, 50],
      pageSize: 10,
      total: 0,
    }
  },
  created() {
    this.query()
  },
  methods:{
    query() {
      // 请求表格数据
      var params ={
        'pageNum': this.currentPage,
        'pageSize': this.pageSize,
        'name':this.searchForm.name,
        'tel':this.searchForm.tel,
        'sex':this.searchForm.sex
      }
      getCompetitionList(params).then(res => {
        // 把请求到的数据给testDatas数组
        this.tableData = res.data.list
        // 当前页数
        this.currentPage = res.data.pageNum
        // 当前页数量
        this.pageSize = res.data.pageSize
        // 分页总数
        this.total = res.data.total
      //   console.log(JSON.stringify(res.data.data.total))
      })
      .catch((error) => {
        console.log(error)
      })
    },
    selectionChange(val) {
      this.selectionList = []
      val.forEach(element => {
        this.selectionList.push(element.id)
      });
    },
    handleSizeChange(val) {
      // 改变每页条数
      this.pageSize = val
      this.query()
    },
    handleCurrentChange(val) {
      // 切换页码
      this.currentPage = val
      this.query()
    },
    handleCurrentChange(val) {
      // 切换页码
      this.currentPage = val
      this.query()
    },
    handleAgree(index,row) {
      getApplyCan(row.id).then(res => {
        if(res.code == 200) {
          this.$router.push({name:'choosecompetition',params:{id:row.id}})
        }
      })
    }
  }
}
</script>

<style>
.info-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 20px;
}
.form {
  margin: 40px auto 20px;
}
</style>
